//
//  MineSetting.swift
//  casdon_swiftUI
//
//  Created by ww on 2025/5/1.
//

import SwiftUI
import FlowStacks

struct MineSettingView: View {
   
    @StateObject var viewModel = MineSettingViewModel()
    var body: some View {
        VStack {
            NavigationBar(title: "设置")
            SettingListView(viewModel: viewModel)
            Spacer()
        }.background(AppColors.Gray1)
    }
}

struct SettingListView: View {
    @EnvironmentObject var navigator: FlowNavigator<MineStack>
    @ObservedObject var viewModel: MineSettingViewModel
    var stackKey: String?
    
    var body: some View {
        VStack(spacing: 0) {
            SettingListItem( title: LocalizedStringKey("account and safe"), subtitle: ""){
                navigator.push(.exploreRecord)
            }
            .padding(.top, 10)
            Divider()
                .frame(height: 1)
                .background(AppColors.Gray2.opacity(0.3))
                .padding(.horizontal, 16)
            
            SettingListItem(title: LocalizedStringKey("region area"), subtitle: viewModel.region){
                navigator.push(.serviceCenter)
            }
            Divider()
                .frame(height: 1)
                .background(AppColors.Gray2)
                .padding(.horizontal, 16)
            SettingListItem(title: LocalizedStringKey("time zone"), subtitle: viewModel.cacheCount){
                navigator.push(.mineSetting)
            }
            Divider()
                .frame(height: 1)
                .background(AppColors.Gray2)
                .padding(.horizontal, 16)
            SettingListItem(title: LocalizedStringKey("clear cache"), subtitle: ""){
                navigator.push(.mineSetting)
            }
            
            ////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
            SettingListItem(title: LocalizedStringKey("ablout casdon"), subtitle: ""){
                navigator.push(.mineSetting)
            }
                .padding(.top, 10)
        }
        .padding(.horizontal, 12)
        .padding(.top, 18)
    }
}


struct SettingListItem: View {
    let title: LocalizedStringKey
    let subtitle: String
    let onTap: () -> Void
    var body: some View {
        Button(action: {
            onTap()
        }) {
            HStack {
                Text(title)
                    .font(.system(size: 16))
                    .foregroundColor(AppColors.Gy1)
                    .padding(.leading, 12)
                Spacer()
                Text(subtitle)
                    .font(.system(size: 16))
                    .foregroundColor(AppColors.Gy3)
                    .padding(.trailing, 6)
                Image(systemName: "chevron.right")
                    .foregroundColor(Color(red: 0.82, green: 0.82, blue: 0.89))
            }
            .padding(.horizontal, 12)
            .frame(height: 56)
            .background(AppColors.White1)
            
        }
    }
}
